home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------*/
- /* */
- /* TEXTWIN.H */
- /* */
- /* Header file for Dispatcher, WinData, and TextWindow */
- /* */
- /*------------------------------------------------------------------------*/
-
- #if !defined( TEXTWIN_H )
- #define TEXTWIN_H
-
- #include <windows.h>
- #include <limits.h>
- #include <string.h>
- #include <vectimp.h>
- #include <stdtempl.h>
-
- /*------------------------------------------------------------------------*/
- /* */
- /* class Dispatcher */
- /* */
- /* Registers callback function to handle dispatching to */
- /* derived classes. */
- /* */
- /*------------------------------------------------------------------------*/
-
- class Dispatcher
- {
- protected:
- Dispatcher() { Window = this; }
- static LONG FAR PASCAL _export Callback( HWND, UINT, UINT, LONG );
- virtual int Dispatch( UINT, UINT, LONG, LONG& ) = 0;
- private:
- static Dispatcher *Window;
- };
-
- /*------------------------------------------------------------------------*/
- /* */
- /* enum FuncType */
- /* template struct DispatchRecord */
- /* */
- /* Used to implement function dispatch database. */
- /* */
- /*------------------------------------------------------------------------*/
-
- enum FuncType
- {
- VoidType,
- UUType,
- UType
- };
-
- template <class T> struct DispatchRecord
- {
- typedef long (T::*VoidFunc)();
- typedef long (T::*UUFunc)( unsigned, unsigned );
- typedef long (T::*UFunc)( unsigned );
- DispatchRecord() {};
- DispatchRecord( UINT m, FuncType t, VoidFunc p )
- { Msg = m; Type = t; Proc = p; }
- int operator == ( const DispatchRecord<T>& m )
- { return Msg == m.Msg; }
- int operator < ( const DispatchRecord<T>& m )
- { return Msg < m.Msg; }
- UINT Msg;
- FuncType Type;
- VoidFunc Proc;
- };
-
- /*------------------------------------------------------------------------*/
- /* */
- /* template <class T> void RegisterProc() */
- /* */
- /* Function templates to handle typesafe member */
- /* function registration. */
- /* */
- /*------------------------------------------------------------------------*/
-
- template <class T> inline void RegisterProc( int msg, long (T::*Proc)() )
- {
- T::Register( msg, VoidType, (DispatchRecord<T>::VoidFunc)Proc );
- }
-
- template <class T>
- inline void RegisterProc( int msg, long (T::*Proc)( unsigned, unsigned ) )
- {
- T::Register( msg, UUType, (DispatchRecord<T>::VoidFunc)Proc );
- }
-
- template <class T>
- inline void RegisterProc( int msg, long (T::*Proc)( unsigned ) )
- {
- T::Register( msg, UType, (DispatchRecord<T>::VoidFunc)Proc );
- }
-
- /*------------------------------------------------------------------------*/
- /* */
- /* class WinData */
- /* */
- /* Stores and maintains basic data about the window. */
- /* */
- /*------------------------------------------------------------------------*/
-
- class WinData : public virtual Dispatcher
- {
- public:
- static void Register( UINT m, FuncType t,
- DispatchRecord<WinData>::VoidFunc p )
- { Map.add( DispatchRecord<WinData>(m,t,p) ); }
- protected:
- WinData() {RegisterProc( WM_SIZE, &WinData::OnSize ); }
- long OnSize( unsigned, unsigned );
- virtual void Resized() {};
- unsigned GetWinHeight() const { return WinHeight; }
- unsigned GetWinWidth() const { return WinWidth; }
- unsigned GetCharHeight() const { return CharHeight; }
- unsigned GetCharWidth() const { return CharWidth; }
- HWND GetHandle() const { return Handle; }
- void SetHandle( HWND );
- virtual int Dispatch( UINT, UINT, LONG, LONG& );
- private:
- unsigned WinHeight;
- unsigned WinWidth;
- unsigned CharHeight;
- unsigned CharWidth;
- HWND Handle;
- static BI_SVectorImp<DispatchRecord<WinData> > Map;
- };
-
- /*------------------------------------------------------------------------*/
- /* */
- /* class TextWindow */
- /* */
- /* Displays static text in a non-scrollable window. */
- /* */
- /*------------------------------------------------------------------------*/
-
- class TextWindow : public virtual WinData, public virtual Dispatcher
- {
- public:
- TextWindow()
- {
- RegisterProc( WM_PAINT, &TextWindow::OnPaint );
- RegisterProc( WM_DESTROY, &TextWindow::OnDestroy );
- }
- void Create( HWND, int, DWORD = 0 );
- static void Register( UINT m, FuncType t, DispatchRecord<TextWindow>::VoidFunc p )
- { Map.add( DispatchRecord<TextWindow>( m, t, p ) ); }
- protected:
- long OnPaint();
- long OnDestroy();
- virtual int GetXPos() const { return 0; }
- virtual int GetYPos() const { return 0; }
- virtual int Dispatch( UINT, UINT, LONG, LONG& );
- static int Lines();
- static int Width() { return MaxWidth; }
- private:
- int RegisterClass( HWND );
- int CreateWindow( HWND, DWORD );
- static BI_SVectorImp<DispatchRecord<TextWindow> > Map;
- static char *Text[];
- static int MaxWidth;
- static int FindWidest();
- };
-
- #endif // TEXTWIN_H
-